﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Cinema_Ticketing_System.Models;
using Cinema_Ticketing_System.Models.Cinema;
using Cinema_Ticketing_System.Models.Film;
using Cinema_Ticketing_System.Models.User;
namespace Cinema_Ticketing_System.Models.User
{
    /// <summary>
    /// 用户
    /// </summary>
    public class User
    {
        CinemaDBEntities2 db = new CinemaDBEntities2();
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int ChangeUserMessage(user_table user)
        {
            user_table user1 = GetUser(user.userid);

            user1.username = user.username;
            user1.userpassword = user.userpassword;
            user1.userphone = user.userphone;

            return db.SaveChanges();
        }

        public int AddUser(user_table user)
        {
            db.user_table.Add(user);

            return db.SaveChanges();
        }

        /// <summary>
        /// 根据用户id获取用户所有信息
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public user_table GetUser (int userid)
        {
            user_table user = db.user_table.SingleOrDefault(x=>x.userid==userid);

            return user;
        }
        /// <summary>
        /// 获得用户订单详细信息
        /// </summary>
        /// <param name="detail_Tables"></param>
        /// <returns></returns>
        public List<UserIdentMessage> GetUSerIdentMessage(List<detail_table> detail_Tables)
        {
            //新建电影院和电影类
            Films films = new Films();
            Cinemas cinemas = new Cinemas();
            //新建用户信息数组
            List<UserIdentMessage> msg = new List<UserIdentMessage>();
            foreach (detail_table item in detail_Tables)
            {
                UserIdentMessage userIdentMessage = new UserIdentMessage() {
                    detaillid = item.detailid,
                    ciname = cinemas.GetCinemaMessage((int)item.cinemaid).cinemaname,
                    seet = item.seatnumber,
                    filmname = films.GetFilmMsg((int)item.filmid).filmname,
                    time = films.GetPlayMsg((int)item.playid).playtime,
                };
                //将获得的对象添加到数组中去
                msg.Add(userIdentMessage);
            }

            return msg;
        }



    }
}